<script setup>
import { useRouter } from 'vue-router'
import { ref, onMounted, onUnmounted } from 'vue'
import FloatingEmojis from '../components/FloatingEmojis.vue'

const router = useRouter()
let typingInterval = null

// 路由导航函数
const navigateTo = (path) => {
  router.push(path)
}

// 终端打字机效果
let terminalLines = [
  '$ <span class="terminal-command">启动 AI 旅游攻略中心</span>',
  '正在加载全球旅游数据...',
  'AI 旅游模型初始化完成',
  '系统就绪 <span class="terminal-cursor">█</span>'
]
let currentLineIndex = 0
let currentCharIndex = 0
const terminalContent = ref(null)

// 终端打字机效果
const startTerminalTypingEffect = () => {
  const terminalContentEl = terminalContent.value
  if (!terminalContentEl) return
  
  terminalContentEl.innerHTML = ''
  
  const typeNextChar = () => {
    if (currentLineIndex >= terminalLines.length) return
    
    const currentLine = terminalLines[currentLineIndex]
    
    if (currentCharIndex === 0) {
      const lineElement = document.createElement('div')
      lineElement.className = 'terminal-line'
      terminalContentEl.appendChild(lineElement)
    }
    
    const currentLineElement = terminalContentEl.lastChild
    if (currentCharIndex < currentLine.length) {
      // 处理HTML标签
      if (currentLine[currentCharIndex] === '<') {
        // 找到标签结束位置
        const tagEndIndex = currentLine.indexOf('>', currentCharIndex)
        if (tagEndIndex !== -1) {
          const tag = currentLine.substring(currentCharIndex, tagEndIndex + 1)
          currentLineElement.innerHTML += tag
          currentCharIndex = tagEndIndex + 1
        } else {
          currentCharIndex++
        }
      } else {
        currentLineElement.innerHTML += currentLine[currentCharIndex]
        currentCharIndex++
      }
      
      typingInterval = setTimeout(typeNextChar, 30)
    } else {
      currentLineIndex++
      currentCharIndex = 0
      typingInterval = setTimeout(typeNextChar, 500)
    }
  }
  
  typeNextChar()
}

onMounted(() => {
  // 终端打字机效果
  startTerminalTypingEffect()
  
  // 终端光标闪烁效果
  const cursor = document.querySelector('.terminal-cursor')
  if (cursor) {
    setInterval(() => {
      const currentOpacity = window.getComputedStyle(cursor).opacity
      cursor.style.opacity = currentOpacity === '0' ? '1' : '0'
    }, 500)
  }
})

onUnmounted(() => {
  if (typingInterval) {
    clearTimeout(typingInterval)
  }
})
</script>

<template>
  <div class="home-container">
    <FloatingEmojis />

    <!-- 装饰元素 -->
    <div class="decoration-container">
      <div class="decoration-dot"></div>
      <div class="decoration-dot"></div>
      <div class="decoration-dot"></div>
    </div>

    <!-- 终端界面 -->
    <div class="terminal-container">
      <div class="terminal-header">
        <div class="terminal-dots">
          <span></span>
          <span></span>
          <span></span>
        </div>
        <div class="terminal-title">终端</div>
      </div>
      <div class="terminal-content" ref="terminalContent"></div>
    </div>
    
    <div class="header">
      <div class="title-container">
        <h1 class="glitch" data-text="AI 旅游中心">AI 旅游中心</h1>
        <div class="subtitle">// 探索全球旅行 //</div>
      </div>
    </div>
    
    <div class="app-cards">
      <div class="app-card" @click="navigateTo('/travel-guide')">
        <div class="card-content">
          <div class="app-icon">
            <svg viewBox="0 0 24 24" class="icon-svg">
              <path d="M20.5,3L20.34,3.03L15,5.1L9,3L3.36,4.9C3.15,4.97 3,5.15 3,5.38V20.5A0.5,0.5 0 0,0 3.5,21L3.66,20.97L9,18.9L15,21L20.64,19.1C20.85,19.03 21,18.85 21,18.62V3.5A0.5,0.5 0 0,0 20.5,3M10,5.47L14,6.87V18.53L10,17.13V5.47M5,6.46L8,5.45V17.15L5,18.31V6.46M19,17.54L16,18.55V6.86L19,5.7V17.54Z" fill='currentColor' />
            </svg>
          </div>
          <div class="card-text">
            <h2>AI <span class="highlight">旅游攻略</span></h2>
            <p>与AI旅游专家聊天，获取旅游规划和目的地推荐</p>
          </div>
        </div>
        <div class="card-overlay"></div>
        <div class="card-border"></div>
      </div>
      
      <div class="app-card" @click="navigateTo('/super-agent')">
        <div class="card-content">
          <div class="app-icon">
            <svg viewBox="0 0 24 24" class="icon-svg">
              <path d="M22,14H21C21,10.13 17.87,7 14,7H13V5.73C13.6,5.39 14,4.74 14,4C14,2.9 13.1,2 12,2C10.9,2 10,2.9 10,4C10,4.74 10.4,5.39 11,5.73V7H10C6.13,7 3,10.13 3,14H2C1.45,14 1,14.45 1,15V18C1,18.55 1.45,19 2,19H3V20C3,21.1 3.9,22 5,22H19C20.1,22 21,21.1 21,20V19H22C22.55,19 23,18.55 23,18V15C23,14.45 22.55,14 22,14M21,17H19V20H5V17H3V16H5V14C5,11.24 7.24,9 10,9H14C16.76,9 19,11.24 19,14V16H21V17M8.5,13.5C7.67,13.5 7,14.17 7,15C7,15.83 7.67,16.5 8.5,16.5C9.33,16.5 10,15.83 10,15C10,14.17 9.33,13.5 8.5,13.5M15.5,13.5C14.67,13.5 14,14.17 14,15C14,15.83 14.67,16.5 15.5,16.5C16.33,16.5 17,15.83 17,15C17,14.17 16.33,13.5 15.5,13.5Z" fill='currentColor' />
            </svg>
          </div>
          <div class="card-text">
            <h2>AI <span class="highlight">超级智能体</span></h2>
            <p>体验超级智能AI，解答各种问题和提供帮助</p>
          </div>
        </div>
        <div class="card-overlay"></div>
        <div class="card-border"></div>
      </div>
    </div>
  </div>
</template>

<style scoped>
.home-container {
  max-width: 1000px;
  margin: 0 auto;
  padding: 2rem;
  text-align: center;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  position: relative;
  z-index: 1;
  overflow: hidden;
  background-color: var(--bg-color);
}

/* 终端样式 */
.terminal-container {
  background-color: #0a0a0a;
  border-radius: 8px;
  width: 100%;
  max-width: 600px;
  margin: 0 auto 2rem;
  overflow: hidden;
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
  transform: perspective(800px) rotateX(5deg);
  transition: all 0.4s ease;
  border: 1px solid rgba(0, 243, 255, 0.2);
  position: relative;
  z-index: 2;
}

.terminal-container:hover {
  transform: perspective(800px) rotateX(0deg);
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5), 0 0 20px var(--neon-green);
  border-color: var(--neon-green);
}

.terminal-header {
  background-color: #1a1a1a;
  padding: 0.5rem 1rem;
  display: flex;
  align-items: center;
  border-bottom: 1px solid #333;
}

.terminal-dots {
  display: flex;
  gap: 6px;
}

.terminal-dots span {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background-color: #ff5f56;
}

.terminal-dots span:nth-child(2) {
  background-color: #ffbd2e;
}

.terminal-dots span:nth-child(3) {
  background-color: #27c93f;
}

.terminal-title {
  margin-left: 1rem;
  font-size: 0.8rem;
  color: #aaa;
}

.terminal-content {
  padding: 1rem;
  text-align: left;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.9rem;
  line-height: 1.5;
  color: #ddd;
  min-height: 150px;
}

.terminal-line {
  margin-bottom: 0.5rem;
  white-space: pre-wrap;
  overflow: hidden;
}

.terminal-command {
  color: var(--neon-green);
}

.terminal-cursor {
  color: var(--neon-green);
  font-weight: bold;
  animation: blink 1s infinite;
}

@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

/* 浮动代码片段 */
.floating-code {
  position: absolute;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.8rem;
  color: rgba(0, 243, 255, 0.3);
  pointer-events: none;
  z-index: -1;
  white-space: nowrap;
}

@keyframes float {
  0% {
    transform: translateY(0) rotate(0deg);
  }
  50% {
    transform: translateY(-20px) rotate(5deg);
  }
  100% {
    transform: translateY(0) rotate(0deg);
  }
}

/* 标题样式 */
.header {
  margin-bottom: 3rem;
  position: relative;
}

.title-container {
  position: relative;
  display: inline-block;
}

.glitch {
  font-size: 3.5rem;
  font-weight: 700;
  text-transform: uppercase;
  position: relative;
  text-shadow: 0 0 10px var(--neon-blue);
  margin-bottom: 0.5rem;
  letter-spacing: 2px;
}

.glitch::before,
.glitch::after {
  content: attr(data-text);
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  opacity: 0.8;
}

.glitch::before {
  color: var(--neon-blue);
  z-index: -1;
  animation: glitch-effect 2s infinite;
}

.glitch::after {
  color: var(--neon-purple);
  z-index: -2;
  animation: glitch-effect 3s infinite reverse;
}

@keyframes glitch-effect {
  0% {
    transform: translate(0);
  }
  20% {
    transform: translate(-3px, 3px);
  }
  40% {
    transform: translate(-3px, -3px);
  }
  60% {
    transform: translate(3px, 3px);
  }
  80% {
    transform: translate(3px, -3px);
  }
  100% {
    transform: translate(0);
  }
}

.subtitle {
  font-size: 1rem;
  color: var(--neon-green);
  letter-spacing: 3px;
  margin-top: -0.5rem;
  font-family: 'JetBrains Mono', monospace;
}

/* 卡片容器 */
.app-cards {
  display: flex;
  justify-content: center;
  gap: 2.5rem;
  margin: 2rem 0;
  flex-wrap: wrap;
  position: relative;
  z-index: 2;
}

/* 卡片样式 */
.app-card {
  background-color: var(--card-bg);
  border-radius: 8px;
  width: 320px;
  height: 200px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  transition: all 0.4s ease;
  box-shadow: 0 10px 20px rgba(0, 0, 0, 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
}

.card-content {
  position: relative;
  z-index: 2;
  padding: 1.5rem;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.card-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(135deg, rgba(0, 243, 255, 0.1) 0%, rgba(157, 0, 255, 0.1) 100%);
  opacity: 0;
  transition: opacity 0.4s ease;
}

.card-border {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  border: 1px solid rgba(0, 243, 255, 0.2);
  border-radius: 8px;
  z-index: 1;
  transition: all 0.4s ease;
}

.app-card:hover {
  transform: translateY(-10px) scale(1.02);
  box-shadow: 0 15px 30px rgba(0, 0, 0, 0.3), 0 0 20px var(--neon-blue);
}

.app-card:hover .card-overlay {
  opacity: 1;
}

.app-card:hover .card-border {
  border-color: var(--neon-blue);
  box-shadow: 0 0 15px var(--neon-blue), inset 0 0 15px var(--neon-blue);
  animation: borderPulse 1.5s infinite alternate;
}

@keyframes borderPulse {
  0% {
    box-shadow: 0 0 15px var(--neon-blue), inset 0 0 15px var(--neon-blue);
  }
  100% {
    box-shadow: 0 0 5px var(--neon-blue), inset 0 0 5px var(--neon-blue);
  }
}

.app-card:hover .icon-svg {
  transform: scale(1.1);
  filter: drop-shadow(0 0 8px var(--neon-blue));
  animation: iconPulse 2s infinite alternate;
}

@keyframes iconPulse {
  0% {
    filter: drop-shadow(0 0 8px var(--neon-blue));
  }
  100% {
    filter: drop-shadow(0 0 15px var(--neon-purple));
  }
}

.app-card:hover h2 .highlight {
  text-shadow: 0 0 10px var(--neon-blue);
  animation: textGlow 1.5s infinite alternate;
}

@keyframes textGlow {
  0% {
    text-shadow: 0 0 10px var(--neon-blue);
    color: var(--neon-blue);
  }
  100% {
    text-shadow: 0 0 20px var(--neon-purple);
    color: var(--neon-purple);
  }
}

/* 图标样式 */
.app-icon {
  margin-bottom: 1rem;
  width: 60px;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background-color: rgba(23, 26, 36, 0.8);
  box-shadow: 0 0 15px rgba(0, 0, 0, 0.2);
  transition: all 0.4s ease;
}

.icon-svg {
  width: 36px;
  height: 36px;
  color: var(--neon-blue);
  transition: all 0.4s ease;
}

/* 文本样式 */
.card-text h2 {
  margin-bottom: 0.5rem;
  font-size: 1.5rem;
  font-weight: 600;
}

.highlight {
  color: var(--neon-blue);
  transition: all 0.3s ease;
}

.card-text p {
  color: #aaa;
  font-size: 0.9rem;
  line-height: 1.4;
}

/* 页脚样式 */
.footer {
  margin-top: 2rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 0;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  font-size: 0.8rem;
  color: #888;
}

.tech-tag {
  font-family: 'JetBrains Mono', monospace;
}

.version {
  opacity: 0.7;
}

/* 浮动颜表情样式 */
.floating-emoji {
  position: fixed;
  font-size: 24px;
  pointer-events: none;
  z-index: 0;
  transition: transform 0.3s ease;
  filter: drop-shadow(0 0 10px rgba(0, 243, 255, 0.3));
  opacity: 0.8;
}

/* 装饰元素样式 */
.decoration-container {
  position: absolute;
  top: 20px;
  right: 20px;
  display: flex;
  gap: 10px;
}

.decoration-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--neon-blue);
  animation: pulse 2s infinite alternate;
}

.decoration-dot:nth-child(2) {
  animation-delay: 0.5s;
  background: var(--neon-purple);
}

.decoration-dot:nth-child(3) {
  animation-delay: 1s;
  background: var(--neon-green);
}

@keyframes pulse {
  0% {
    transform: scale(1);
    opacity: 0.5;
  }
  100% {
    transform: scale(1.5);
    opacity: 1;
  }
}

/* 页脚装饰 */
.footer-decoration {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 20px;
  z-index: 1;
}

.footer-emoji {
  font-size: 24px;
  animation: bounce 2s infinite;
  filter: drop-shadow(0 0 10px rgba(0, 243, 255, 0.5));
}

.footer-emoji:nth-child(2) {
  animation-delay: 0.3s;
}

.footer-emoji:nth-child(3) {
  animation-delay: 0.6s;
}

@keyframes bounce {
  0%, 100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-10px);
  }
}

/* 响应式设计 */
@media (max-width: 1024px) {
  .app-cards {
    gap: 2rem;
  }
  
  .terminal-container {
    max-width: 90%;
  }
  
  .app-card {
    width: 280px;
    height: 180px;
  }
}

@media (max-width: 768px) {
  .app-cards {
    gap: 1.5rem;
    flex-direction: column;
    align-items: center;
  }
  
  .terminal-container {
    max-width: 100%;
  }
  
  .floating-code {
    display: none;
  }
  
  .app-card {
    width: 100%;
    max-width: 320px;
  }
  
  .glitch {
    font-size: 2.5rem;
  }
  
  .home-container {
    padding: 1rem;
  }

  .floating-emoji {
    font-size: 20px;
  }
  
  .footer-emoji {
    font-size: 20px;
  }
  
  .decoration-container {
    top: 10px;
    right: 10px;
  }
}

/* 亮色模式 */
@media (prefers-color-scheme: light) {
  .app-card {
    background-color: var(--card-bg);
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.1);
  }
  
  .card-text p {
    color: #666;
  }
  
  .app-icon {
    background-color: rgba(240, 240, 240, 0.8);
  }
  
  .icon-svg {
    color: var(--neon-purple);
  }
  
  .highlight {
    color: var(--neon-purple);
  }
  
  .app-card:hover {
    box-shadow: 0 15px 30px rgba(0, 0, 0, 0.15), 0 0 20px var(--neon-purple);
  }
  
  .app-card:hover .card-border {
    border-color: var(--neon-purple);
    box-shadow: 0 0 15px var(--neon-purple), inset 0 0 15px var(--neon-purple);
  }
  
  .app-card:hover .icon-svg {
    filter: drop-shadow(0 0 8px var(--neon-purple));
  }
  
  .app-card:hover h2 .highlight {
    text-shadow: 0 0 10px var(--neon-purple);
  }
  
  .footer {
    border-top: 1px solid rgba(0, 0, 0, 0.1);
  }
}
</style>